<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta charset="utf-8">
<title>材料采购</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../../res/css/layui.css" media="all">
<link rel="stylesheet" href="../../res/css/cst/snproduction.css"
	media="all">
<link rel="stylesheet" href="../../res/css/cst/zzsc.css" media="all">
<script type="text/javascript" src="../../res/js/jquery-1.11.2.min.js"></script>
<style>
#purchase tr td, #purchase tr th {
	text-align: center;
}

#purchase {
	margin-bottom: 40px;
}

.materNumber {
	width: 200px;
	height: 28px;
	border: none;
	text-align: center;
}

.materSum {
	width: 200px;
	height: 28px;
	border: none;
	text-align: center;
	color: gray;
	opacity: 0.8;
}
</style>
</head>
<body>

	<div class="demoTable" style="margin-left: 20px; margin-top: 10px;">
		<from class="layui-form"> 用户名称:
		<div class="layui-inline">
			<select lay-filter="aihao" id="userSelect" style="width: 80px;">
			</select>
		</div>

		<div class="layui-inline">
			<label class="layui-form-label">范围</label>
			<div class="layui-input-inline" style="width: 100px;">
				<input type="text" name="price_min" placeholder="￥" id="oneMoney" maxlength="5"
					autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-mid">-</div>
			<div class="layui-input-inline" style="width: 100px;">
				<input type="text" name="price_max" placeholder="￥" id="twoMoney" maxlength="5"
					autocomplete="off" class="layui-input">
			</div>
		</div>

		</from>
		<button class="layui-btn layui-btn-sm" data-type="reload"
			id="selectButton">搜索</button>
		<button class="layui-btn layui-btn-warm layui-btn-sm" id="insert">增加</button>

	</div>

	<table class="layui-table"
		lay-data="{ url:'../../mapurchase/findAll.action', page:true, id:'idTest'}"
		lay-filter="demo">
		<thead>
			<tr>
				<th lay-data="{type:'checkbox', fixed: 'left'}"></th>
				<th lay-data="{field:'purId',width:'250',align:'center'}">材料采购编号</th>
				<th lay-data="{field:'userName',width:'150',sort: true, align:'center'}">用户名称</th>
				<th lay-data="{field:'optime', width:'200',align:'center'}">操作时间</th>
				<th lay-data="{field:'purMoney',width:'150', align:'center'}">采购总金额</th>
				<th lay-data="{field:'purCount',width:'150', align:'center'}">采购总数量</th>
				<th lay-data="{field:'oper', align:'center',width:'150',templet:'#maState'}">采购状态</th>
				<th
					lay-data="{fixed: 'right',fixed: 'right',width:'450',align:'center', toolbar: '#barDemo'}">操作</th>
			</tr>
		</thead>
	</table>

	<script type="text/javascript" id="maState">
	{{# if(d.oper == 0) { }}
		<div>等待提交审核</div>
	{{# }else if(d.oper == 1) { }}
		<div>等待审核</div>
		{{# }else if(d.oper == 2) { }}
	 <div>等待采购</div>
		 {{# } else if(d.oper == 3){ }}
	<div>采购中</div>
	 {{# } else if(d.oper == 4){ }}
		<div>采购完成</div>
	{{# }else if(d.oper == 5){ }}
		<div>等待质检</div>
	 {{# }else if(d.oper == 6){ }}
			<div>质检完成</div>
	 {{# }}}
	</script>

	<script type="text/html" id="barDemo">
	{{# if(d.oper == 0) { }}
     <button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
	 <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
 	{{# } else{ }}
     <button class="layui-btn layui-btn-disabled layui-btn-xs">编辑</button>
	 <button class="layui-btn layui-btn-disabled layui-btn-xs">删除</button>
	{{# }}}
	
	{{# if(d.oper == 0) { }}
     	<button class="layui-btn layui-btn-xs layui-btn-warm" lay-event="audit">提交审核</button>
 	{{# }else if(d.oper == 1){ }}
		<button class="layui-btn layui-btn-xs layui-btn-disabled">等待审核</button>
	{{# }else{ }}
		<button class="layui-btn layui-btn-xs layui-btn-disabled">审核通过</button>
	{{# }}}

	{{# if(d.oper == 3) { }}
     	<button class="layui-btn layui-btn-xs layui-btn-warm" lay-event="accomplish">采购完成</button>
 	{{# } else if(d.oper >3){ }}
    	<button class="layui-btn layui-btn-xs layui-btn-disabled">采购完成</button>
	{{# } else if(d.oper ==2){ }}
		<button class="layui-btn layui-btn-xs layui-btn-warm" lay-event="make">开始采购</button>
	{{# }else{ }}
		<button class="layui-btn layui-btn-xs layui-btn-disabled">开始采购</button>
	{{# }}}

 	{{# if(d.oper == 4) { }}
		<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="addMaQuality">提交质检</button>
	{{# } else if(d.oper == 5){}}
		<button class="layui-btn layui-btn-xs layui-btn-disabled">等待质检</button>
	{{# } else if( d.oper == 6 ){}}
		<button class="layui-btn layui-btn-xs layui-btn-disabled">质检完成</button>
	{{# }else{ }}
		<button class="layui-btn layui-btn-xs layui-btn-disabled">提交质检</button>
	{{#}}}
	
	 <button class="layui-btn layui-btn-xs" lay-event="detail">查看详情</button>
	</script>

	<!-- 增加或修改的弹框 -->
	<div id="addOrUpdate" style="display: none;">
		<div style="width: 100%; height: 560px;">
			<div id="MaterislsLeft"
				style="width: 16%; height: 516px;float: left;background: #f0f0f0;padding: 15px;"></div>

			<div style="width: 80%; float: right;">
				<div class="demoTable" style="margin-left: 20px; margin-top: 10px;">
					<from class="layui-form"> 材料名称:
					<div class="layui-inline">
						<input class="layui-input"  placeholder="请输入材料名称:" maxlength="7"
							style="height: 32px;" id="maName" autocomplete="off">
					</div>
					材料类型:
					<div class="layui-inline">
						<select lay-filter="aihao" id="maTypeSelect" style="width: 80px;">
						</select>
					</div>

					<button class="layui-btn layui-btn-sm" data-type="Materisls"
						id="insertSelect">搜索</button>
					<button class="layui-btn layui-btn-danger layui-btn-sm"
						onclick="exit()">取消</button>
					</from>
				</div>
				<input type="hidden" id="materislsInput" />
				<table id="materisls" class="layui-hide" lay-filter="materislsDemo">

				</table>
			</div>
		</div>


		<div class="demoTable" style="margin-left: 20px; margin-top: 10px;">
			<from class="layui-form"> 采购总金额:
			<div class="layui-inline">
				<input class="layui-input" value="￥" disabled style="height: 32px;"
					id="maxMoney" autocomplete="off">
			</div>

			采购总数量:
			<div class="layui-inline">
				<input class="layui-input" value="￥" disabled style="height: 32px;"
					id="maxCount" autocomplete="off">
			</div>

			<!--  材料供应商:
			<div class="layui-inline">
				<select lay-filter="aihao" id="firmSelect" style="width: 80px;">
				</select>
			</div>--> </from>
			<button class="layui-btn layui-btn-sm" id="baoButton"
				data-type="getSave">确认保存</button>
		</div>
		<input type="hidden" id="purIdInput">
		<table class="layui-table" id="purchase" lay-filter="purchaseDemo">
			<thead>
				<tr>
					<th lay-data="{field:'typeId', align:'center'}">材料编号</th>
					<th lay-data="{field:'typeName', align:'center'}">材料名称</th>
					<th lay-data="{field:'maName', align:'center'}">材料数量(个)</th>
					<th lay-data="{field:'maMoney', align:'center'}">材料单价(元)</th>
					<th lay-data="{field:'maMoney', align:'center'}">小计(元)</th>
				</tr>
			</thead>
			<tbody id="purchaseBody">

			</tbody>
		</table>
		</div>
		<div id="detailDiv" style="display: none;">
		
		<h2 style="margin: 0 auto;text-align: center;">—————————————————材料采购详情—————————————————</h2>
		<table class="layui-table"
			lay-data="{ url:'../../mapurDetail/findAll.action', page:true, id:'mapurDetailId'}"
			lay-filter="demo">
			<thead>
				<tr>
					<th lay-data="{type:'checkbox', fixed: 'left'}"></th>
					<th lay-data="{field:'deId',align:'center'}">材料采购详情编号</th>
					<th lay-data="{field:'maName',sort: true, align:'center'}">材料名称</th>
					<th lay-data="{field:'deNumber', align:'center'}">采购数量</th>
					<th lay-data="{field:'deMoney', align:'center'}">采购单价</th>
					<th lay-data="{field:'deSum', align:'center'}">采购小计</th>
				</tr>
			</thead>
		</table>
	</div>

		<!--  <script type="text/javascript" src="../../res/js/cst/zzsc.js"></script>-->
		<script src="../../res/layui.all.js" charset="utf-8"></script>
		<!-- 动态赋值表格 -->
		<script type="text/javascript">
					layui.use('table', function() {
						var table = layui.table;

						table.render({
							elem : '#materisls',
							page : true,
							url : '../../materials/findAll.action',
							cellMinWidth : 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
							,
							cols : [ [ {
								type : 'checkbox',
								sort : true,
							}, {
								field : 'maId',
								title : '材料编号',
								sort : true,
								align:'center'
							}, {
								field : 'typeName',
								title : '材料类型',
								align:'center'
							}, {
								field : 'maName',
								title : '材料名称',
								align:'center'
							}, {
								field : 'maMoney',
								title : '材料价格',
								align:'center'
							} //minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
							] ]
							//表格加载完成的回调函数
							,
							done : function(res, curr, count) {
								var count=0;
								$.each($(".layui-table-col-special"),function(index,item){
									console.info($(item).next().children().html());
									if($(item).next().children().html()!=undefined && $(item).next().next().children().html()!=''){
										$.each($("#materislsInput").val().split("@"),function(indexs,items){
											if(items==($(item).next().children().html())){
												console.info($(item).children().children(":first"));
												var check=$(item).children().children(":first").get(0);
												$(check).attr({"checked":true});
												
												console.info($(check).get(0).checked);
												if($(check).get(0).checked){
													count++;
												}
												load();
											}
										});
									};
								});
								/*console.info("选中的行数"+(count)+table.cache.materisls.length);
								var th=$('#materisls').next().find('.layui-table-header th').get(0);
					            var checkboxId=$(th).find('input[name="layTableCheckbox"]');
								if((count)==table.cache.materisls.length){
									console.info(checkboxId);
									$(checkboxId).attr({"checked":true});
								}else{
									console.info(checkboxId);
									$(checkboxId).attr({"checked":false});
								}
								setTimeout(function(){
									load();
								},200);*/
							}
						});
					});
				</script>

		<script type="text/javascript" src="../../res/js/cst/snmapurchase.js"></script>
</body>
</html>